<template>
  <div>
    <el-dialog title="修改密码"
               :visible.sync="dialogVisible"
               width="30%"
               :close-on-click-modal="false">
      <el-form>
        <el-form-item label="原密码">
          <el-input v-model="passInfo.userPwd"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="passInfo.newPwd"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="passInfo.surePwd"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary"
                   @click="editPass">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { editPassword } from '../api/common'
export default {
  name: "safe",
  props: ["dialogVisible"],
  methods: {
    cancel () { //关闭
      this.$emit("send", false)
    },
    async editPass () {//修改密码
      // editPassword().then(res => { }).catch(err => { })
      if (this.passInfo.newPwd === this.passInfo.surePwd) {
        var res = await editPassword({
          userPwd: this.passInfo.userPwd,
          newPwd: this.passInfo.newPwd
        })
        if (res.success) {
          this.$alert("修改密码成功")
          this.$router.push("/login")
          this.$emit("send", false)
        }
        if (res.err) {
          this.$alert(res.err)
        }
      } else {
        this.$alert("俩次密码不一致")
      }
    }
  },

  data () {
    return {
      passInfo: {
        userPwd: "",
        newPwd: "",
        surePwd: ""
      }
    }
  }
}
</script>
<style lang="less">
</style>